﻿Imports BUS
Imports DTO

Public Class MH_PhanQuyenSuDung

    Dim dsLND As New List(Of LoaiNguoiDungDTO)

    Private Sub MH_PhanQuyenSuDung_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Load danh sach loai nguoi dung
        Dim lndBUS As New LoaiNguoiDungBUS
        dsLND = lndBUS.LayDanhSach()
        cboLoaiNguoiDung.DataSource = dsLND
        cboLoaiNguoiDung.DisplayMember = ("TenLoaiNguoiDung")
        cboLoaiNguoiDung.ValueMember = ("MaLoaiNguoiDung")

        Dim index As Integer = cboLoaiNguoiDung.SelectedIndex
        chkBangDiem.Checked = dsLND(index).BangDiem
        chkBaoBieu.Checked = dsLND(index).BaoBieu
        chkDanhSach.Checked = dsLND(index).DanhSach
        chkPhatSinh.Checked = dsLND(index).PhatSinh
        chkQuanTri.Checked = dsLND(index).QuanTri
        chkTraCuu.Checked = dsLND(index).TraCuu
    End Sub


    Private Sub cboLoaiNguoiDung_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLoaiNguoiDung.SelectedIndexChanged
        Dim index As Integer = cboLoaiNguoiDung.SelectedIndex
        chkBangDiem.Checked = dsLND(index).BangDiem
        chkBaoBieu.Checked = dsLND(index).BaoBieu
        chkDanhSach.Checked = dsLND(index).DanhSach
        chkPhatSinh.Checked = dsLND(index).PhatSinh
        chkQuanTri.Checked = dsLND(index).QuanTri
        chkTraCuu.Checked = dsLND(index).TraCuu

    End Sub

    Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        Me.Close()
    End Sub

    Private Sub btnCapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhat.Click
        Dim lndDTO As New LoaiNguoiDungDTO
        lndDTO.MaLoaiNguoiDung = dsLND(cboLoaiNguoiDung.SelectedIndex).MaLoaiNguoiDung
        lndDTO.DanhSach = chkDanhSach.Checked
        lndDTO.PhatSinh = chkPhatSinh.Checked
        lndDTO.BaoBieu = chkBangDiem.Checked
        lndDTO.TraCuu = chkTraCuu.Checked
        lndDTO.BangDiem = chkBangDiem.Checked
        lndDTO.QuanTri = chkQuanTri.Checked

        Dim lndBUS As New LoaiNguoiDungBUS
        Dim r As Integer = lndBUS.CapNhatQuyenSuDung(lndDTO)

        If r = 1 Then
            dsLND = lndBUS.LayDanhSach()
            MessageBox.Show("Thành công !!!")
        Else
            MessageBox.Show("Thất bại.")
        End If

    End Sub
End Class